package com.heima.juc.n4;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * @author : leimingchao
 * @date Date : 2022年02月12日 22:53
 */
public class UnsafeAccessor {

    private static final Unsafe UNSAFE;

    static {
        Field theUnsafe = null;
        try {
            theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
            theUnsafe.setAccessible(true);
            UNSAFE = (Unsafe) theUnsafe.get(null);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            throw new Error(e);
        }

    }


    public static Unsafe getUnsafe() {
        return UNSAFE;
    }
}
